Skip to content

Fix text sent as input to rufo - #21

Merged
lucerion merged 2 commits into
ruby-formatter:masterfrom
13k:fix-rufo-input
May 22, 2018
Merged

lucerion merged 2 commits into
ruby-formatter:masterfrom
13k:fix-rufo-input

Conversation

@13k

@13k 13k commented May 21, 2018 •

Copy link
Copy Markdown
Contributor

The text being sent to rufo is incorrectly formed with lines joined by the actual characters \n, instead of an actual single-char newline.

This fixes #17 and fixes #18.

@13k

13k commented May 21, 2018

Copy link
Copy Markdown
Contributor Author

It still breaks with code containing \, like:

var2 = \
  case var1
  end

Removing the \ escaping works, but I'm not sure if will break on other scenarios.

@13k

13k commented May 21, 2018

Copy link
Copy Markdown
Contributor Author

I've added a commit to remove the escaping, since shellescape should already escape everything needed when passing as a shell argument to echo.

@splattael splattael left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@13k Thank again!

I have trouble to make @blasterpal's code from #17 to work.

This code still give an error - even with your patch:

Code

module JIRA
  class Client
    def find!(*args)
      begin
        self.find(*args)
      rescue JIRA::HTTPError
        puts "Object not found"
        nil
      end
    end
  end
end

Result

rufo-vim-invalid

@13k Any ideas?

@13k

13k commented May 21, 2018

Copy link
Copy Markdown
Contributor Author

I think this is related to #19, which I fixed again. I've merged #19 and this one and that snippet formats correctly for me.

@13k

13k commented May 21, 2018

Copy link
Copy Markdown
Contributor Author

peek 2018-05-21 16-23

@lucerion

Copy link
Copy Markdown
Member

Could you, please, recheck #12?

@13k

13k commented May 22, 2018

Copy link
Copy Markdown
Contributor Author

@lucerion It looks correct:

peek 2018-05-22 11-35

My reasoning here is, essentially, that the correct approach is to always send the unmodified input to rufo, emulating cat <file> | rufo. The command should receive \ chars as \ chars, newlines as actual newlines, and so on.

I tried to research a way to avoid echoing the contents and piping to the program's stdin, but looks like vim doesn't support it. The examples I found use python to spawn a child process and directly emit the text to the child's stdin. Despite it being common for modern vim plugins to require +python, I'm not sure if the added complexity/dependencies are worth the benefits here.

@lucerion
lucerion merged commit 009a62d into ruby-formatter:master May 22, 2018
@13k
13k deleted the fix-rufo-input branch May 22, 2018 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: the given text is not a valid ruby program (it has syntax errors) Rufo and Rails (it has syntax errors?)

3 participants